<!DOCTYPE html>
<html lang="en">
<include file="CommonSidebar:common-head"/>
<link href="__ROOT__/Application/Admin/Public/css/jquery.datetimepicker.css" rel="stylesheet">
<body>
<link href="__ROOT__/Application/Admin/Public/css/cropper/cropper.min.css" rel="stylesheet">
<link href="__ROOT__/Application/Admin/Public/css/main.css" rel="stylesheet">
<js href="__ROOT__/Application/Admin/Public/ueditor/ueditor.config.js"/>
<js href="__ROOT__/Application/Admin/Public/ueditor/ueditor.all.min.js"/>
<js href="__ROOT__/Application/Admin/Public/js/jquery-2.0.2.js"/>

<!--编辑器-->
<js href="__ROOT__/Application/Admin/Public/ueditor/ueditor.config.js"/>
<js href="__ROOT__/Application/Admin/Public/ueditor/ueditor.all.min.js"/>
<script>
    $(function () {
        var ue = UE.getEditor('container');
    });
</script>

<div id="wrapper">

    <!-- Navigation -->
    <include file="CommonSidebar:common-navbar"/>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">添加/编辑文章</h1>
            </div>
        </div>

        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                            <div class="panel panel-default">
                                <div class="panel-heading" role="tab" id="headingOne">
                                    <h4 class="panel-title">
                                        <a role="button" data-toggle="collapse" data-parent="#accordion"
                                           href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                            添加/编辑文章
                                        </a>
                                    </h4>
                                </div>
                                <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel"
                                     aria-labelledby="headingOne">
                                    <div class="panel-body">
                                        <form id="editStoreForm" action="{:U('EditAdd')}"
                                              class="form-horizontal"
                                              method="post">

                                            <input name="ID" type="hidden" value="{$DATA['ID']}">
                                            <if condition="$BookData">
                                                <label class="col-sm-2 control-label">书籍</label>

                                                <div class="form-group">
                                                    <div class="col-sm-4">
                                                        <img width="200px" src="{$BookData['PIC_URL']}">
                                                    </div>
                                                </div>
                                                <else/>
                                                <if condition="$ID">
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">插入书籍ISBN:</label>

                                                        <div class="col-sm-4">
                                                            <input type="text" class="form-control" name="BOOK_ID"
                                                                   id="BOOK_ID" value="{$DATA['BOOK_ID']}">
                                                        </div>
                                                    </div>
                                                </if>
                                            </if>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">文章标题:</label>

                                                <div class="col-sm-8">

                                                    <input id="two" type="text" class="form-control" name="TITLE"
                                                           value="{$DATA['TITLE']}">

                                                </div>
                                            </div>

                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">文章主体内容:</label>

                                                <div class="col-sm-8">
                                                    <script id="container" id="CONTENT" name="CONTENT"
                                                            type="text/plain" required>{$DATA.DATA}



                                                    
                                                    
                                                    


                                                    </script>
                                                </div>
                                            </div>


                                            <div class="form-group">
                                                <div class="col-sm-2 col-sm-offset-2">
                                                    <button type="submit" class="btn btn-block btn-primary">保存
                                                    </button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>

    </div>
    <!-- /#page-wrapper -->

</div>


<!--书籍列表-->
<div id="BOOKLIST" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog"
     aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title text-center">书籍列表</h4>
            </div>
            <div class="modal-body">
                <table id="my-orders" class="table table-responsive table-bordered" style="margin-top: 10px"
                       border="0">
                    <tr style="color: #008200;color-interpolation: red;align-content: center">
                        <th width="5px" style="text-align:center"></th>
                        <th style="text-align:center">图片</th>
                        <th style="text-align:center" width="200px">书名</th>
                        <th style="text-align:center">作者</th>
                        <th style="text-align:center">出版社</th>
                        <th style="text-align:center">包装</th>
                        <th style="text-align:center">定价</th>
                    </tr>
                    <tbody id="context">
                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
<!--书籍列表-->

<include file="CommonSidebar:common-script"/>
<!-- Custom Theme JavaScript -->
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>
<script type="text/javascript" src="__ROOT__/Application/Admin/Public/js/uploadPreview.js"></script>
<script type="text/javascript" src="__ROOT__/Application/Admin/Public/js/jquery.form.min.js"></script>
<script type="text/javascript" src="__ROOT__/Application/Admin/Public/js/jquery.qrcode.min.js"></script>


<include file="Common:common-cropper"/>
<script src="__ROOT__/Application/Admin/Public/dist/js/sb-admin-2.js"></script>
<script type="text/javascript" src="__ROOT__/Application/Admin/Public/js/bootstrapValidator.js"></script>
<script src="__ROOT__/Application/Admin/Public/js/cropper/cropper.min.js"></script>
<script src="__ROOT__/Application/Admin/Public/js/figure.js"></script>


</body>
<script>
    $("select#status").change(function () {
        var ID = $(this).val();
        $.post("{:U('GetRegion_two')}",
                {ID: ID},
                function (data) {
                    $("#two").empty();
                    $.each(data, function (n, value) {
                        $("#two").append("<option value='" + value.region_name + "'>" + value.region_name + "</option>");
                    });

                });
    });
</script>
<script>


    // 绑定键盘按下事件
    $(document).keypress(function (e) {
        // 回车键事件
        if (e.which == 13 && $('#BOOKLIST').hasClass('in')) {
            var ID = '';
            var A_ID = '{$ID}';
            $("input[name='checkbox_s']:checkbox:checked").each(function (index, item) {
                ID = $(this).val();
            });
            $.post("{:U('AddBookToArticles')}",
                    {ID: ID, A_ID: A_ID},
                    function (data) {
                        console.log(data);
                        if (data) {
                            alert('插入书籍成功');
                            window.location.reload();
                        } else {
                            alert('插入书籍失败');
                        }
                    });
        }

    });

    //搜索书籍
    //输入框回车事件
    $("#BOOK_ID").change(function () {
        var ISBN = $(this).val();
        $.post("{:U('GetBookToISBN')}", {ISBN: ISBN}, function (data) {
            console.log(data);
            if (data) {
                $("#context").html("");
                for (var i in data) {
                    var html = '';
                    html += '<tr>';
                    if (i == 0) {
                        html += "<td ><input name='checkbox_s' value='" + data[i]['ID'] + "' type='checkbox' checked></td>";
                    } else {
                        html += "<td ><input name='checkbox_s' value='" + data[i]['ID'] + "' type='checkbox'></td>";
                    }
                    html += '<td ><img width="50px" src="' + data[i]['PIC_URL'] + '"></td>';
                    html += '<td >' + data[i]['TITLE'] + '</td>';
                    html += '<td >' + data[i]['AUTHOR'] + '</td>';
                    html += '<td >' + data[i]['PRESS'] + '</td>';
                    html += '<td >' + data[i]['PACKING_SPECIFICATION'] + '</td>';
                    html += '<td >' + data[i]['Y_PRICE'] + '</td>';
                    html += '</tr>';
                    $("#context").append(html);
                }
                $('#BOOKLIST').modal('show');
            }
        });

    });


    $(function () {
        new CropAvatar({
            container: '#crop-avatar',
            workspaces: '__ROOT',
            formUrl: "{:U('Pics/Pics')}",
            submitDone: function (data) {
                console.log(data);
                var $avatarView = $('.avatar-view');
                if (data.state == 1) {
                    var imgUrl = data.picpath;
                    var imgUrlTH = data.data;
                    var html = ' <div class="goods-img-item">';
                    html += '<img style="height: 250px" src="' + '__ROOT__/' + imgUrl + '" alt="">';
                    html += '<span class="glyphicon close-goods-img glyphicon-remove-circle"></span>';
                    html += '<input type="hidden" value="' + imgUrlTH + '" name="thumbpicpath[]" >';
                    html += ' <input type="hidden" value="' + imgUrl + '" name="picpath[]" >';
                    html += '</div>';
                    $avatarView.before(html);
                } else {
                    alert('Failed to response');
                }
            },
            delete: function (e) {
                var _this = e.target;
                var flag = _this.className.indexOf('close-goods-img');
                var $avatarView = $('.avatar-view');
                if (flag >= 0) {
                    var $elem = $(_this);
                    if (confirm("确认移除？")) {
                        $avatarView.show();
                        $elem.parent(".goods-img-item").remove();
                        $avatarView.next("input[name='thumbpicpath']").val("");
                        $avatarView.next("input[name='picpath']").val("");
                        $('.add-goods-img').attr('src', options.workspaces + '/Public/Boss/images/default.png')
                    }
                }
            }

        });
    });

    function submitcheck() {
        var $picid = $("input[name='picid']");
        if ($picid.val() == "") {
            $picid.parents(".form-group").removeClass("has-success").addClass("has-error");
            $picid.parents(".form-group").find(".help-block").show();
            return false;
        }
    }
</script>
</html>
